<!DOCTYPE html>
<html lang="en">

<head>
    <title></title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="css/style.css" rel="stylesheet">
</head>

<body>
    <script>
        // let n = 3
        let n = 4
        for (let i = 0; i < n; i++) {
            let arr = []
            if (n % 2 == 0 && i % 2 == 1) {
                for (let j = n; j > 0; j--) {
                    arr.push(i * n + j)
                }
            } else {
                for (let j = 1; j <= n; j++) {
                    arr.push(i * n + j)
                }
            }
            console.log(arr.join(" "))
        }
    </script>
</body>

</html>